import sys

"""
读取并显示VCF文件内容的脚本
用法: python read_vcf.py [vcf文件路径]
"""

def read_vcf_file(file_path):
    try:
        # 使用UTF-8编码读取文件
        with open(file_path, 'r', encoding='utf-8') as f:
            content = f.read()
            print("VCF文件内容:\n")
            print(content)
            return True
    except FileNotFoundError:
        print(f"错误: 找不到文件 '{file_path}'")
    except UnicodeDecodeError:
        # 如果UTF-8解码失败，尝试其他常见编码
        try:
            with open(file_path, 'r', encoding='gbk') as f:
                content = f.read()
                print("使用GBK编码读取的VCF文件内容:\n")
                print(content)
                return True
        except:
            print(f"错误: 无法解码文件 '{file_path}'")
    except Exception as e:
        print(f"读取文件时出错: {e}")
    return False

if __name__ == "__main__":
    # 默认读取test_contacts.vcf文件
    file_path = "test_contacts.vcf"
    
    # 如果命令行提供了文件路径参数，则使用该参数
    if len(sys.argv) > 1:
        file_path = sys.argv[1]
    
    print(f"正在读取文件: {file_path}\n")
    read_vcf_file(file_path)